package cn.base.demo3;

public class Code15 {
    public static void main(String[] args) {
        int[] arr1 = {11, 1, 3};
        if (arr1.length == 0) {
            System.out.println("数组为空");
        } else {
            System.out.println(test(arr1)[0]);
            System.out.println(test(arr1)[1]);
        }

    }

    /**
     * 获取一个数组的最大值和最小值
     *
     * @param arr 要处理的数组
     * @return 返回最大值和最小值
     */
    public static int[] test(int[] arr) {
        int max = arr[0];
        int min = arr[0];
        for (int i = 0; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        int[] arr1 = {max, min};
        return arr1;
    }

}
